package cn.green.core.components.store.table;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import cn.green.core.components.exceptions.DefaultTypeNullException;
import cn.green.core.components.table.TableTypeCom;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wang.yishu
 * @version 1.0
 * @className TableTypeStore
 * @description 仓库
 * @date 2024/11/20 13:39
 */
public class TableTypeStore {

    private static final Map<String, TableTypeCom> TABLE_TYPE_COM_MAP = new HashMap<>();
    private static final JSONArray OPTIONS = new JSONArray();

    public static void put(TableTypeCom store) {
        TABLE_TYPE_COM_MAP.put(store.dataTypeCode(), store);
        JSONObject option = new JSONObject();
        option.put("label", store.dataTypeName());
        option.put("value", store.dataTypeCode());
        OPTIONS.add(option);
    }

    public static TableTypeCom get(String typeCode) {
        if (!TABLE_TYPE_COM_MAP.containsKey(typeCode)) {
            throw new DefaultTypeNullException(typeCode);
        }
        return TABLE_TYPE_COM_MAP.get(typeCode);
    }

    public static JSONArray options() {
        return OPTIONS;
    }

}
